{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "1c96427c",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import torch"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "a169a2a1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "torch.Size([2, 3])\n",
      "torch.FloatTensor\n",
      "<class 'torch.Tensor'>\n",
      "True\n"
     ]
    }
   ],
   "source": [
    "# 类型推断\n",
    "# randn(2, 3) 生产2行3列的正态分布随机数，均值为0方差为1【N(0, 1)】\n",
    "a = torch.randn(2, 3)\n",
    "print(a.shape)\n",
    "print(a.type())\n",
    "print(type(a))\n",
    "print(isinstance(a, torch.FloatTensor))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b8e6a665",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 存放位置不一样，类型检测也会不一样\n",
    "isinstance(data, torch.cuda.DoubleTensor)\n",
    "\n",
    "data = data.cuda()\n",
    "\n",
    "isinstance(data, torch.cuda.DoubleTensor)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bdae4df1",
   "metadata": {},
   "source": [
    "#### 标量\n",
    "- 一般用来计算loss"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "958da1dd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor(1.)\n",
      "tensor(1.3000)\n"
     ]
    }
   ],
   "source": [
    "print(torch.tensor(1.))\n",
    "print(torch.tensor(1.3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "82ca6d19",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "torch.Size([])\n",
      "0\n",
      "torch.Size([])\n",
      "0\n"
     ]
    }
   ],
   "source": [
    "a = torch.tensor(2.2)\n",
    "print(a.shape)\n",
    "print(len(a.shape))\n",
    "print(a.size())\n",
    "print(a.dim())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d1d7dd48",
   "metadata": {},
   "source": [
    "#### 一维"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "5e51dbba",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([1.1000])\n",
      "1\n",
      "tensor([1.1000, 2.2000])\n",
      "tensor([-1.0842e-19])\n",
      "tensor([-1.0842e-19,  1.8875e+00])\n",
      "[1. 1.]\n",
      "tensor([1., 1.], dtype=torch.float64)\n"
     ]
    }
   ],
   "source": [
    "print(torch.tensor([1.1]))\n",
    "print(torch.tensor([1.1]).dim())\n",
    "\n",
    "print(torch.tensor([1.1, 2.2]))\n",
    "\n",
    "# dimension=1，len=1的向量\n",
    "print(torch.FloatTensor(1))\n",
    "# dimension=1，len=2的向量\n",
    "print(torch.FloatTensor(2))\n",
    "\n",
    "data = np.ones(2)\n",
    "print(data)\n",
    "\n",
    "# numpy类型转为tensor，数据类型：dtype=torch.float64\n",
    "print(torch.from_numpy(data))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "70e45230",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[-0.0429, -0.4606,  0.5519],\n",
      "        [-2.5553,  0.6087,  2.9079]])\n",
      "torch.Size([2, 3])\n",
      "2\n",
      "3\n",
      "3\n",
      "tensor([0.3940, 0.2063, 0.3936])\n",
      "torch.Size([3])\n"
     ]
    }
   ],
   "source": [
    "# 二维数据 dimension=2\n",
    "a = torch.randn(2, 3)\n",
    "print(a)\n",
    "print(a.shape)\n",
    "print(a.size(0))\n",
    "print(a.size(1))\n",
    "print(a.shape[1])\n",
    "\n",
    "b = torch.randn(3)\n",
    "print(b)\n",
    "print(b.shape)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5f71038e",
   "metadata": {},
   "source": [
    "#### 使用场景（RNN）\n",
    "- 一句话的词向量表达[10, 100] \n",
    "1. 每句话有10个单词\n",
    "2. 每个单词有100个one-hot编码的feature\n",
    "- 多句话的词向量表达[10, 20, 100]\n",
    "1. 每句话有10个单词\n",
    "2. 每次送入20个句子\n",
    "3. 每个单词有100个one-hot编码的feature\n",
    "\n",
    "#### 四维向量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "7397ed01",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[[[ 6.4233e-01, -9.6398e-01, -1.0220e+00,  ...,  1.4758e+00,\n",
      "            1.6705e+00,  2.6283e+00],\n",
      "          [ 1.4357e+00, -9.8250e-01,  2.0339e+00,  ...,  1.1311e+00,\n",
      "            1.0489e-01, -1.1635e+00],\n",
      "          [-2.7755e-01, -2.2248e+00, -2.2371e-01,  ..., -2.2252e+00,\n",
      "           -1.5762e-01,  5.2915e-01],\n",
      "          ...,\n",
      "          [-9.5208e-01,  9.8235e-02, -5.4048e-01,  ...,  3.7181e-02,\n",
      "            8.1896e-01,  9.1202e-01],\n",
      "          [ 1.4077e+00,  3.8345e-01,  8.8889e-01,  ..., -9.3595e-01,\n",
      "            3.9322e-01,  1.3037e-01],\n",
      "          [ 1.8605e+00, -8.9666e-01,  4.5081e-01,  ...,  1.0261e+00,\n",
      "            1.2017e+00, -1.0603e+00]],\n",
      "\n",
      "         [[ 2.2327e+00, -2.9744e-01, -8.0964e-01,  ...,  1.9252e+00,\n",
      "            1.4342e+00,  8.5719e-01],\n",
      "          [ 9.6729e-01, -4.9987e-01,  1.1880e+00,  ...,  5.2475e-01,\n",
      "           -3.2556e-01, -1.4458e+00],\n",
      "          [ 1.1124e+00, -3.2453e-01, -9.6992e-01,  ...,  1.5635e+00,\n",
      "            2.6172e-01, -1.4461e+00],\n",
      "          ...,\n",
      "          [ 1.2120e+00, -6.8712e-01, -2.8402e-02,  ..., -3.0955e-01,\n",
      "           -6.6256e-01,  7.4723e-01],\n",
      "          [-2.3272e-02,  1.1332e-03,  4.1067e-01,  ...,  8.5694e-01,\n",
      "            4.7521e-01, -8.1823e-01],\n",
      "          [ 1.7085e+00,  1.1823e+00, -8.6726e-01,  ..., -1.6562e-01,\n",
      "           -3.1177e-01,  1.1218e+00]],\n",
      "\n",
      "         [[ 1.8049e+00, -2.4868e-01,  7.6666e-01,  ...,  1.0700e+00,\n",
      "            1.8015e-01,  1.1242e+00],\n",
      "          [ 7.5142e-01,  1.3244e+00, -7.6542e-01,  ...,  9.5542e-01,\n",
      "           -7.7194e-01,  8.7831e-01],\n",
      "          [-5.4974e-01, -1.0202e-01, -8.9794e-01,  ...,  2.1323e-01,\n",
      "           -2.0223e+00,  8.8359e-01],\n",
      "          ...,\n",
      "          [ 1.1862e+00, -6.6467e-01, -1.1256e+00,  ..., -1.2858e+00,\n",
      "            1.7946e+00,  1.9864e-01],\n",
      "          [-6.9058e-01,  6.3409e-01, -9.3675e-02,  ..., -1.5632e+00,\n",
      "           -9.9244e-01,  4.3780e-01],\n",
      "          [-5.5537e-01, -4.4113e-01, -4.4429e-01,  ...,  8.8819e-01,\n",
      "            2.1861e+00,  9.2212e-01]]],\n",
      "\n",
      "\n",
      "        [[[-1.0464e-02, -6.9500e-01,  5.5945e-01,  ..., -1.9157e-01,\n",
      "           -1.3298e+00,  3.3841e-01],\n",
      "          [ 1.6910e-01, -1.0395e+00, -5.5910e-01,  ..., -1.1679e+00,\n",
      "            2.2603e+00,  5.8220e-01],\n",
      "          [-5.9888e-02,  1.1138e-01,  1.3406e+00,  ...,  4.2324e-01,\n",
      "            4.1216e-02,  9.7506e-02],\n",
      "          ...,\n",
      "          [-1.6873e-01, -3.2308e-01,  7.0669e-01,  ...,  5.7869e-01,\n",
      "           -1.9561e-01,  9.5206e-01],\n",
      "          [ 1.2300e-02,  9.0257e-01,  1.5098e+00,  ..., -2.4361e-01,\n",
      "            1.1664e+00,  7.8952e-01],\n",
      "          [ 1.3668e+00,  5.9051e-01, -9.7096e-01,  ..., -7.0967e-01,\n",
      "           -1.6006e-02, -7.9392e-01]],\n",
      "\n",
      "         [[-3.8474e-01, -1.9736e-01, -3.6132e-01,  ...,  2.2398e-01,\n",
      "           -2.7760e-01, -1.2161e+00],\n",
      "          [ 4.1855e-02, -1.9914e+00,  1.1629e+00,  ...,  1.3210e+00,\n",
      "            9.7983e-01,  2.6733e-01],\n",
      "          [ 1.2488e+00,  6.2015e-01, -2.3170e-01,  ...,  6.2897e-01,\n",
      "           -3.3178e-01,  2.2021e+00],\n",
      "          ...,\n",
      "          [ 6.6166e-01,  9.7417e-02, -1.0503e+00,  ..., -1.0442e-01,\n",
      "            4.6336e-01,  7.9778e-01],\n",
      "          [ 7.3586e-01, -7.2024e-01, -7.8699e-02,  ...,  1.1040e+00,\n",
      "            9.6887e-01, -5.6650e-01],\n",
      "          [ 1.3116e+00, -3.3617e-01,  9.2220e-01,  ...,  9.5068e-02,\n",
      "            2.0124e-02, -1.0653e+00]],\n",
      "\n",
      "         [[-2.5556e-02,  2.6122e-01,  5.1542e-01,  ...,  4.8281e-01,\n",
      "           -4.7248e-01, -2.5559e-01],\n",
      "          [ 2.0425e-01,  1.2326e+00,  1.1765e+00,  ..., -6.2861e-01,\n",
      "           -9.8426e-02, -1.0301e+00],\n",
      "          [-1.1746e-01, -6.1978e-01, -5.8150e-01,  ...,  2.0192e+00,\n",
      "           -5.3467e-01,  7.8633e-01],\n",
      "          ...,\n",
      "          [ 1.0610e+00, -1.7975e+00, -7.0844e-01,  ..., -1.6840e+00,\n",
      "            9.6271e-01, -1.2843e+00],\n",
      "          [-2.5142e-01,  2.3459e-01, -4.1532e-01,  ...,  8.9487e-01,\n",
      "           -4.1146e-01,  1.1919e+00],\n",
      "          [ 7.3634e-01,  1.6340e+00, -7.0664e-01,  ..., -3.3318e-01,\n",
      "            2.3366e+00,  1.0205e+00]]]])\n",
      "torch.Size([2, 3, 28, 28])\n",
      "4704\n",
      "4\n"
     ]
    }
   ],
   "source": [
    "a = torch.randn(2, 3, 28, 28)\n",
    "\n",
    "print(a)\n",
    "print(a.shape)\n",
    "\n",
    "# numel：占用内存的数量\n",
    "print(a.numel())\n",
    "\n",
    "# 维度\n",
    "print(a.dim())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d86cb902",
   "metadata": {},
   "source": [
    "- 四维向量适合图片处理，如：2张图片，3个（RGB）通过，每个通道长宽28 * 28"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e1f94c8b",
   "metadata": {},
   "source": [
    "## 创建Tensor"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "3951a551",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([2, 3, 3], dtype=torch.int32)\n",
      "tensor([[1., 1., 1.],\n",
      "        [1., 1., 1.]], dtype=torch.float64)\n"
     ]
    }
   ],
   "source": [
    "# 从numpy创建tensor\n",
    "a = np.array([2, 3, 3])\n",
    "print(torch.from_numpy(a))\n",
    "\n",
    "a = np.ones([2, 3])\n",
    "print(torch.from_numpy(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "c94de590",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([2.0000, 3.2000])\n",
      "tensor([2.0000, 3.2000, 0.0000])\n",
      "tensor([[2.1349e+20, 1.6537e-04, 8.5456e-07],\n",
      "        [2.1009e+20, 5.2119e-11, 7.1450e+31]])\n",
      "tensor([2.0000, 3.2000])\n",
      "tensor([[ 2.0000,  3.2000],\n",
      "        [ 1.0000, 22.3000]])\n"
     ]
    }
   ],
   "source": [
    "# 从list创建tensor\n",
    "# 小写tensor接收直接数据作为参数\n",
    "print(torch.tensor([2. ,3.2]))\n",
    "# 大写Tensor接收维度作为参数\n",
    "print(torch.Tensor(3))\n",
    "# 维度参数\n",
    "print(torch.FloatTensor(2, 3))\n",
    "# 直接数据参数\n",
    "print(torch.FloatTensor([2., 3.2]))\n",
    "print(torch.tensor([[2., 3.2], [1., 22.3]]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "0b42c51c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([9.2302e+21])\n"
     ]
    }
   ],
   "source": [
    "# 创建未初始化的tensor，需要在后续指定确定的值\n",
    "print(torch.empty(1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "0edbc47d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "torch.FloatTensor\n",
      "torch.DoubleTensor\n"
     ]
    }
   ],
   "source": [
    "# 设置默认的tensor类型\n",
    "print(torch.tensor([1.2, 3]).type())\n",
    "\n",
    "torch.set_default_tensor_type(torch.DoubleTensor)\n",
    "\n",
    "print(torch.tensor([1.2, 3]).type())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6ded415d",
   "metadata": {},
   "source": [
    "#### 随机初始化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "00188a2f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[0.3072, 0.3529, 0.3744],\n",
      "        [0.6465, 0.3023, 0.8831],\n",
      "        [0.7183, 0.8724, 0.0920]])\n",
      "tensor([[0.0412, 0.3888, 0.1728],\n",
      "        [0.6997, 0.4283, 0.1833],\n",
      "        [0.8611, 0.0168, 0.0319]])\n",
      "tensor([[3.8344, 3.1791, 8.9716],\n",
      "        [4.0720, 0.2545, 8.5724]])\n",
      "tensor([[3, 8, 6],\n",
      "        [9, 1, 2],\n",
      "        [4, 5, 3]])\n"
     ]
    }
   ],
   "source": [
    "# rand 会随机产生 0 - 1 之间的数值，不包括 1\n",
    "print(torch.rand(3, 3))\n",
    "\n",
    "a = torch.rand(3, 3)\n",
    "\n",
    "# 生产和指定向量（a）的shape相同的随机值向量\n",
    "print(torch.rand_like(a))\n",
    "\n",
    "# 采样0 - 10 的tensor\n",
    "print(10 * torch.rand(2, 3))\n",
    "\n",
    "# shape= 3*3, 大于等于1，小于10的随机数\n",
    "print(torch.randint(1, 10, [3, 3]))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7d75ed68",
   "metadata": {},
   "source": [
    "#### 正态分布初始化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "bded52ed",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[ 1.5015, -0.8311,  2.4736],\n",
      "        [ 0.5194,  0.1798, -0.8974],\n",
      "        [ 0.1169, -0.1572, -0.0835]])\n",
      "tensor([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])\n",
      "tensor([1.0000, 0.9000, 0.8000, 0.7000, 0.6000, 0.5000, 0.4000, 0.3000, 0.2000,\n",
      "        0.1000])\n"
     ]
    }
   ],
   "source": [
    "# 均值为0，方差为1\n",
    "print(torch.randn(3, 3))\n",
    "\n",
    "# 指定均值和方差分布\n",
    "# print(torch.normal(mean=torch.full([10], 0)))\n",
    "\n",
    "# print(torch.normal(mean=torch.full([10], 0), std=torch.arange(1, 0, -0.1)))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "113e6eef",
   "metadata": {},
   "source": [
    "#### 初始化一个值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "534f470f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[7, 7, 7],\n",
      "        [7, 7, 7]])\n",
      "tensor(7)\n",
      "tensor([7, 7])\n"
     ]
    }
   ],
   "source": [
    "# 2行3列\n",
    "print(torch.full([2, 3], 7))\n",
    "# 标量\n",
    "print(torch.full([], 7))\n",
    "# 一维\n",
    "print(torch.full([2], 7))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ed332561",
   "metadata": {},
   "source": [
    "#### 初始化等差数列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "4c17c757",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])\n",
      "tensor([0, 2, 4, 6, 8])\n",
      "tensor([ 0.,  1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.,  9., 10.])\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\Users\\ASUS\\AppData\\Local\\Temp\\ipykernel_1576\\2586338375.py:5: UserWarning: torch.range is deprecated and will be removed in a future release because its behavior is inconsistent with Python's range builtin. Instead, use torch.arange, which produces values in [start, end).\n",
      "  print(torch.range(0, 10))\n"
     ]
    }
   ],
   "source": [
    "print(torch.arange(0, 10))\n",
    "\n",
    "print(torch.arange(0, 10, 2))\n",
    "# 不建议使用range\n",
    "print(torch.range(0, 10))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2fd37a36",
   "metadata": {},
   "source": [
    "#### 初始化等差数列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "3c3e0ee0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([ 0.0000,  3.3333,  6.6667, 10.0000])\n",
      "tensor([ 0.0000,  1.1111,  2.2222,  3.3333,  4.4444,  5.5556,  6.6667,  7.7778,\n",
      "         8.8889, 10.0000])\n",
      "tensor([ 0.,  1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.,  9., 10.])\n",
      "tensor([1.0000, 0.7743, 0.5995, 0.4642, 0.3594, 0.2783, 0.2154, 0.1668, 0.1292,\n",
      "        0.1000])\n",
      "tensor([ 1.0000,  1.2915,  1.6681,  2.1544,  2.7826,  3.5938,  4.6416,  5.9948,\n",
      "         7.7426, 10.0000])\n"
     ]
    }
   ],
   "source": [
    "print(torch.linspace(0, 10, steps=4))\n",
    "\n",
    "print(torch.linspace(0, 10, steps=10))\n",
    "\n",
    "print(torch.linspace(0, 10, steps=11))\n",
    "\n",
    "# logspace 的 base 参数可以设置为 2，10，e等底数\n",
    "print(torch.logspace(0, -1, steps=10))\n",
    "\n",
    "print(torch.logspace(0, 1, steps=10))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "99b764d4",
   "metadata": {},
   "source": [
    "#### 其他"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "id": "cd9b36aa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([[1., 1., 1.],\n",
      "        [1., 1., 1.],\n",
      "        [1., 1., 1.]])\n",
      "tensor([[0., 0., 0.],\n",
      "        [0., 0., 0.],\n",
      "        [0., 0., 0.]])\n",
      "tensor([[1., 0., 0.],\n",
      "        [0., 1., 0.],\n",
      "        [0., 0., 1.]])\n",
      "tensor([[1., 0., 0., 0.],\n",
      "        [0., 1., 0., 0.],\n",
      "        [0., 0., 1., 0.]])\n",
      "tensor([[1., 1., 1.],\n",
      "        [1., 1., 1.],\n",
      "        [1., 1., 1.]])\n"
     ]
    }
   ],
   "source": [
    "# 全1\n",
    "print(torch.ones(3, 3))\n",
    "# 全0\n",
    "print(torch.zeros(3, 3))\n",
    "\n",
    "# 单位矩阵\n",
    "print(torch.eye(3))\n",
    "print(torch.eye(3, 4))\n",
    "\n",
    "a = torch.zeros(3, 3)\n",
    "print(torch.ones_like(a))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b9d61cdf",
   "metadata": {},
   "source": [
    "#### 随机打散"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "f57fe7c4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tensor([9, 1, 8, 6, 4, 3, 0, 7, 5, 2])\n"
     ]
    }
   ],
   "source": [
    "print(torch.randperm(10))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a4a2efd6",
   "metadata": {},
   "outputs": [],
   "source": [
    "a = torch.rand(2, 3)\n",
    "b = torch.rand(2, 3)\n",
    "idx = torch.randperm(2)\n",
    "print(idx)\n",
    "\n",
    "print(a[idx])\n",
    "print(b[idx])\n",
    "\n",
    "print(a)\n",
    "print(b)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
